/**
 * 获取菜单,递归自己，理论上无限级菜单
 */
function gettreemenu(ta,pid)
{
	var ohtml = "[";                        
	for(var i=0;i<ta.length;i++){
		var tmpgm = "";
		if((ta[i].pid == pid)){
			ohtml += '{name:"' + ta[i].title + '",id:"' + ta[i].id + '",icon:"' + ta[i].icon + '"';
			tmpgm = gettreemenu(ta,ta[i].id);
			if(tmpgm.length>10){
				ohtml += ',children:' + tmpgm;
			}
			ohtml += "},";
		}
	}
	ohtml += "]";
	return ohtml;
}

/**
 * 获取上级模块菜单名
 * @param datalist
 * @param pid 
 * @return pidname
 */
function get_pid_name(datalist,pid){
	if(datalist && pid){
		for(var i=0;i<datalist.length;i++){
			if(datalist[i].id==pid){
				return datalist[i].title;
			}
		}
	}
	return '';
}

/**
 * 获取上级名
 * @param datalist
 * @param pid 
 * @return pidname
 */
function get_pid_name_k(datalist,pid,key){
	if(datalist && pid){
		for(var i=0;i<datalist.length;i++){
			if(datalist[i].id==pid){
				return datalist[i][key];
			}
		}
	}
	return '';
}


/**
 * 获取维修项目
 */
function gettreeitemclass(ta,pid)
{
	var ohtml = "[";                        
	for(var i=0;i<ta.length;i++){
		var tmpgm = "";
		if((ta[i].pid == pid)){
			ohtml += '{name:"' + ta[i].name + '",id:"' + ta[i].id + '"';
			tmpgm = gettreeitemclass(ta,ta[i].id);
			if(tmpgm.length>10){
				ohtml += ',children:' + tmpgm;
			}
			ohtml += "},";
		}
	}
	ohtml += "]";
	return ohtml;
}


/**
 * 树型全部展开获取维修项目
 */
function gettreeitemspread(ta,pid)
{
	var ohtml = "[";                        
	for(var i=0;i<ta.length;i++){
		var tmpgm = "";
		if((ta[i].pid == pid)){
			ohtml += '{name:"' + ta[i].name + '",id:"' + ta[i].id + '"';
			tmpgm = gettreeitemspread(ta,ta[i].id);
			if(tmpgm.length>10){
				ohtml += ',spread:true,children:' + tmpgm;
			}
			ohtml += "},";
		}
	}
	ohtml += "]";
	return ohtml;
}

function GetQueryString(name) {
    let index = tstr.indexOf('?')
    let str = tstr.substring(index + 1);
    let arr = str.split('&');
    let result = {};
    arr.forEach((item) => {
        let a = item.split('=');
        result[a[0]] = a[1];
    })
    return result[name];
}

//实现将数字金额转换为大写人民币汉字的方法
function convertCurrency(a){var e="\u96f6\u58f9\u8d30\u53c1\u8086\u4f0d\u9646\u67d2\u634c\u7396".split(""),k=["","\u62fe","\u4f70","\u4edf"],m=["","\u4e07","\u4ebf","\u5146"],n=["\u89d2","\u5206","\u6beb","\u5398"],b="";if(""==a)return"";a=parseFloat(a);if(1E15<=a)return"";if(0==a)return b=e[0]+"\u5143\u6574";a=a.toString();if(-1==a.indexOf("."))var d="";else d=a.split("."),a=d[0],d=d[1].substr(0,4);if(0<parseInt(a,10)){for(var g=0,l=a.length,c=0;c<l;c++){var f=a.substr(c,1),h=l-c-1,p=h/4;h%=4;"0"==f?g++:(0<g&&(b+=e[0]),g=0,b+=e[parseInt(f)]+k[h]);0==h&&4>g&&(b+=m[p])}b+="\u5143"}if(""!=d)for(k=d.length,c=0;c<k;c++)f=d.substr(c,1),"0"!=f&&(b+=e[Number(f)]+n[c]);""==b?b+=e[0]+"\u5143\u6574":""==d&&(b+="\u6574");return b};

//品牌按首字拼音分组-下拉菜单
//id,name,code
function getcarbrandselect(b,v) {
	for (var c = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""), d = 0; d < e.length; d++) {
		c += '<optgroup label="' + e[d] + '">';
		for (var a = 0; a < b.length; a++) b[a].code == e[d] && (c += '<option value="' + b[a].id + '" '+(b[a].id==v?'selected':'' )+'>' + b[a].name + "</option>");
		c += "</optgroup>"
	}
	return c
};

String.prototype.replaceAll = function(s1,s2){return this.replace(new RegExp(s1,"gm"),s2); }

/**
 * 获取文章类型,递归自己，理论上无限级
 */
function gettreearttype(ta,pid)
{
	var ohtml = "[";                        
	for(var i=0;i<ta.length;i++){
		var tmpgm = "";
		if((ta[i].pid == pid)){
			ohtml += '{"id":"' + ta[i].id + '","label":"' + ta[i].name  + '"';
			tmpgm = gettreearttype(ta,ta[i].id);
			if(tmpgm.length>10){
				ohtml += ',"children":' + tmpgm;
			}
			ohtml += "},";
		}
	}
	ohtml += "]";
	ohtml = ohtml.replaceAll('},]','}]');
	return ohtml;
}
/**
 * 找出下拉TREE默认值
 */
function getselectdefault(ta,pid)
{
	var ohtml = "";                        
	for(var i=0;i<ta.length;i++){
		if((ta[i].id == pid)){
			ohtml = ta[i].name ;
		}
	}
	if(pid==0){
		ohtml="顶级分类";
	}
	return ohtml;
}